<?php
/**
 * Created by PhpStorm.
 * User: Charles
 * Date: 2017/10/9
 * Time: 7:08
 */

namespace app\Http\Controllers\Wechat;


use App\Http\Controllers\Controller;
use App\Models\WechatUpload;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Session;

class RewardController extends Controller
{
    public function getIndex(Request $request)
    {
        $wechatUpload = WechatUpload::query()
            ->where('id', $request->id)
            ->where('openid', Session::get('wechat_openid'))
            ->first();
        if (null === $wechatUpload) {
            abort(400, '非法访问');
        }
        return view('wechat.reward', compact('wechatUpload'));
    }

    public function getUrl(Request $request)
    {
        $wechatUpload = WechatUpload::findOrFail($request->id);
        echo "callback('{$wechatUpload->promotion_url}')";
        exit;
    }
}